﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BaseData_CollocationArticleDetail : System.Web.UI.Page
{
    private string Code
    {
        get
        {
            return Request.QueryString["code"] != null ? Request.QueryString["code"].ToString() : "";
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200300112");
        if (!IsPostBack)
        {
            BindDropCollocationType();
            Bind();
        }
    }

    private void BindDropCollocationType()
    {
        DataTable dtCollocationType = new BLL.DPCategory().GetAllDpCategory().Tables[0];
        dropCollocationType.DataSource = dtCollocationType;
        dropCollocationType.DataTextField = "DP_NAME";
        dropCollocationType.DataValueField = "DP_ID";
        dropCollocationType.DataBind();
    }

    private void Bind()
    {
        Model.CollocationArticle article = new BLL.CollocationArticle().GetModel(this.Code);
        if (article == null)
        {
            Response.Write("<script>alert('系统无法获取到该文章的信息！');window.location.href='CollocationArticleMain.aspx'</script>");
        }

        txtTitle.Text = article.Title;
        for (int i = 0; i < dropCollocationType.Items.Count; i++)
        {
            if (dropCollocationType.Items[i].Value == article.ArticleTypeId)
            {
                dropCollocationType.SelectedIndex = i;
                break;
            }
        }
        WebEditor1.Text = article.Content;
    }


    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300112", "00002"))
        {
            Share.Alert(Page, "无权操作"); return;
        }
        Model.CollocationArticle article = new BLL.CollocationArticle().GetModel(this.Code);
        if (article == null)
        {
            Response.Write("<script>alert('系统无法获取到该文章的信息！');window.location.href='CollocationArticleMain.aspx'</script>");
        }
        article.Title = txtTitle.Text;
        article.ArticleTypeId = dropCollocationType.SelectedValue;
        article.Content = WebEditor1.Text;
        if (new BLL.CollocationArticle().Update(article))
        {
            Share.InsertLog("200300112", "00002");
            Share.Alert(this.Page,"修改成功！");
        }
        else
        {
            Share.Alert(this.Page,"修改失败！");
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {

    }
}
